geo.utils.ts ➔ getDistance   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1 12
import * as turf from '@turf/turf';
2
3 12
export function getDistance(lat1: number, lon1: number, lat2: number, lon2: number) {
4 50
  const from = turf.point([lon1, lat1]);
5 50
  const to = turf.point([lon2, lat2]);
6 50
  return turf.distance(from, to) * 1000;
7
}
8
9 12
export function positionInsidePolygon(
10
  lat: number,
11
  lon: number,
12
  polygon: { lat: number; lng: number }[],
13
): boolean {
14 486
  const point = {
15
    type: 'Feature' as const,
16
    properties: {},
17
    geometry: {
18
      type: 'Point' as const,
19
      coordinates: [lon, lat],
20
    },
21
  };
22 486
  const poly = {
23
    type: 'Feature' as const,
24
    properties: {},
25
    geometry: {
26
      type: 'Polygon' as const,
27 2469
      coordinates: [polygon.map((p) => [p.lng, p.lat])],
28
    },
29
  };
30 486
  return turf.booleanPointInPolygon(point, poly);
31
}
32